
# include "dfxFileWriter.h"

namespace DFX
{
    DFXRESULT FileWriter::Open(const String &fileName)
    {
        mFileName = fileName;

        mMapFile = fopen(mFileName.c_str(), "w");

        if (!mMapFile)
            return DFX_OPENFAILED;

        return DFX_SUCCESS;
    }

    void FileWriter::Close()
    {
        if (mMapFile)
            fclose(mMapFile);

        mMapFile = NULL;
    }

    void FileWriter::Seek(UInt64 position)
    {
        if (mMapFile != NULL)
            fseek(mMapFile, static_cast<UInt32>(position), SEEK_SET);

        mPosition = position;
    }

    UInt64 FileWriter::Write(const void *buffer, UInt64 size)
    {
        if (mMapFile != NULL)
            fwrite(buffer, static_cast<UInt32>(size), 1, mMapFile);

        mPosition += size;

        return size;
    }
}